package sivin.uikit.adapter;

import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.viewbinding.ViewBinding;

import java.util.List;

public abstract class SimpleAdapter<T, Binding extends ViewBinding> extends CommonAdapter<T> {
    protected List<T> mDatas;

    public SimpleAdapter(List<T> datas) {
        super(datas);
        mDatas = datas;
        addItemViewDelegate(new ItemViewDelegate2<T, Binding>() {
            @Override
            public Binding getViewBinding(ViewGroup parent) {
                return createViewBinding(parent);
            }

            @Override
            public boolean isForViewType(T item, int position) {
                return true;
            }

            @Override
            public void convert(@NonNull ViewHolder<Binding> holder, T t, int position) {
                SimpleAdapter.this.convert(holder, t, position);
            }
        });
    }

    protected abstract Binding createViewBinding(ViewGroup parent);

    protected abstract void convert(ViewHolder<Binding> holder, T t, int position);

}
